package com.ktg.service.impl;

import com.ktg.ktgcommon.domain.TmToolType;
import com.ktg.ktgcommon.filter.TokenVerifyFilter;
import com.ktg.ktgcommon.utils.Page;
import com.ktg.mapper.TmToolTypeMapper;
import com.ktg.service.TmToolTypeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TmToolTypeServiceImpl implements TmToolTypeService {
    @Resource
    private TmToolTypeMapper tmToolTypeMapper;

    @Override
    public Page<TmToolType> findPage(TmToolType entity, Integer pageNo, Integer pageSize) {
        Page<TmToolType> page = new Page<>();
        page.setPageSize(pageSize);
        //查询总数，计算总页数
        Long count = tmToolTypeMapper.count();
        page.setTotalCount(count.intValue());
        page.setPageNo(pageNo);
        //查询分页数据
        List<TmToolType> data = tmToolTypeMapper.findPage(entity, page.offset(), page.getPageSize());
        page.setData(data);
        return page;
    }

    @Override
    public List<TmToolType> maintenTypeList() {
        return tmToolTypeMapper.maintenTypeList();
    }

    @Override
    public boolean update(TmToolType entity) {
        entity.setUpdateBy(TokenVerifyFilter.getUserName().getUsername());
        entity.setUpdateTime(new Date());
        entity.setCreateTime(new Date());
        return tmToolTypeMapper.update(entity);
    }

    @Override
    public boolean add(TmToolType entity) {
        return tmToolTypeMapper.add(entity);
    }

    @Override
    public TmToolType findById(Long toolTypeId) {
        return tmToolTypeMapper.findById(toolTypeId);
    }

    @Override
    public Integer delete(Long toolTypeId) {
        return tmToolTypeMapper.delete(toolTypeId);
    }
}
